package UML_ER.diagram.edit.policies;

import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;

import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
import UML_ER.diagram.edit.commands.BinaryRelationshipCreateCommand;
import UML_ER.diagram.edit.commands.BinaryRelationshipTargetCreateCommand;
import UML_ER.diagram.edit.commands.BinaryRelationshipTargetReorientCommand;
import UML_ER.diagram.edit.commands.RoleCreateCommand;
import UML_ER.diagram.edit.commands.RoleReorientCommand;
import UML_ER.diagram.edit.parts.BinaryRelationshipTargetEditPart;
import UML_ER.diagram.edit.parts.RoleEditPart;
import UML_ER.diagram.providers.UML_ERElementTypes;

/**
 * @generated
 */
public class BinaryRelationship2ItemSemanticEditPolicy extends
		UML_ERBaseItemSemanticEditPolicy {

	/**
	 * @generated
	 */
	public BinaryRelationship2ItemSemanticEditPolicy() {
		super(UML_ERElementTypes.BinaryRelationship_4014);
	}

	protected Command getCreateCommand(CreateElementRequest req) {

		if (UML_ERElementTypes.Attribute_3001 == req.getElementType()) {
			return getGEFWrapper(new BinaryRelationshipCreateCommand(req));
		}
		return super.getCreateCommand(req);
	}

	/**
	 * @generated
	 */
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
		return getGEFWrapper(new DestroyElementCommand(req));
	}

	/**
	 * @generated
	 */
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
		Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req)
				: getCompleteCreateRelationshipCommand(req);
		return command != null ? command : super
				.getCreateRelationshipCommand(req);
	}

	/**
	 * @generated
	 */
	protected Command getStartCreateRelationshipCommand(
			CreateRelationshipRequest req) {
		if (UML_ERElementTypes.BinaryRelationshipTarget_4022 == req
				.getElementType()) {
			return getGEFWrapper(new BinaryRelationshipTargetCreateCommand(req,
					req.getSource(), req.getTarget()));
		}
		if (UML_ERElementTypes.Role_4024 == req.getElementType()) {
			return getGEFWrapper(new RoleCreateCommand(req, req.getSource(),
					req.getTarget()));
		}
		return null;
	}

	/**
	 * @generated
	 */
	protected Command getCompleteCreateRelationshipCommand(
			CreateRelationshipRequest req) {
		if (UML_ERElementTypes.BinaryRelationshipTarget_4022 == req
				.getElementType()) {
			return null;
		}
		if (UML_ERElementTypes.Role_4024 == req.getElementType()) {
			return null;
		}
		return null;
	}

	/**
	 * Returns command to reorient EClass based link. New link target or source
	 * should be the domain model element associated with this node.
	 * 
	 * @generated
	 */
	protected Command getReorientRelationshipCommand(
			ReorientRelationshipRequest req) {
		switch (getVisualID(req)) {
		case RoleEditPart.VISUAL_ID:
			return getGEFWrapper(new RoleReorientCommand(req));
		}
		return super.getReorientRelationshipCommand(req);
	}

	/**
	 * Returns command to reorient EReference based link. New link target or source
	 * should be the domain model element associated with this node.
	 * 
	 * @generated
	 */
	protected Command getReorientReferenceRelationshipCommand(
			ReorientReferenceRelationshipRequest req) {
		switch (getVisualID(req)) {
		case BinaryRelationshipTargetEditPart.VISUAL_ID:
			return getGEFWrapper(new BinaryRelationshipTargetReorientCommand(
					req));
		}
		return super.getReorientReferenceRelationshipCommand(req);
	}

}
